<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .bg {
            background: rgba(0, 0, 0, 0.5);
            position: fixed;
            width: 100vw;
            height: 100vh;
            top: 0;
            left: 0;
        }

        ul,
        li {
            list-style: none;
        }

        .wrap {
            position: fixed;
            bottom: 0;
            width: 100vw;
            text-align: center;
            background: #fff;
            z-index: 999;
        }

        h3 {
            /* border-bottom: 1px solid rgba(71, 22, 183, 1); */
            margin: 10px 10vw;
            padding: 7px 0;
            font-size: 22px;
        }

        .money {
            font-size: 22px;
            margin: 3vh 0;
        }

        .pwd {
            display: flex;
            border: 1px solid #ddd;
            width: 80vw;
            margin: 0 10vw;
            margin-bottom: 10vh;
            background: #fff;
        }

        .pwd .w-list {
            border-right: 1px solid #eee;
            width: calc((80vw - 5px) / 6);
            height: calc((80vw - 5px) / 6);
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .pwd .w-list .yuan {
            width: 10px;
            height: 10px;
            border-radius: 50%;
            background: #fff;
            display: inline-block;
        }

        .pwd .w-list.num .yuan {
            background: #333333;
        }

        .pwd .w-list:last-child {
            border-right: none;
        }

        .keyboard {
            display: flex;
            flex-wrap: wrap;
            background: #fff;
        }

        .keyboard .k-list {
            border-right: 1px solid #eee;
            border-top: 1px solid #eee;
            width: calc((100vw - 2px) / 3);
            text-align: center;
            line-height: 50px;
            font-size: 22px;
        }

        .keyboard .k-list:nth-child(3n) {
            border-right: none;
        }

        .keyboard .del {
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .keyboard .del img {
            width: 30px;
        }
    </style>
</head>

<body>
    <div class="bg" tapmode onclick="api.closeFrame()"></div>
    <div class="wrap" id="view">
        <h3>{{_i18n('请设置支付密码')}}</h3>
        <!-- <div class="money">￥ <span>0</span></div> -->
        <ul class="pwd">
            <li class="w-list"><span class="yuan"></span></li>
            <li class="w-list"><span class="yuan"></span></li>
            <li class="w-list"><span class="yuan"></span></li>
            <li class="w-list"><span class="yuan"></span></li>
            <li class="w-list"><span class="yuan"></span></li>
            <li class="w-list"><span class="yuan"></span></li>
        </ul>
        <ul class="keyboard">
            <li class="k-list" onclick="getnum(1)" data-key=1>1</li>
            <li class="k-list" onclick="getnum(2)" data-key=2>2</li>
            <li class="k-list" onclick="getnum(3)" data-key=3>3</li>
            <li class="k-list" onclick="getnum(4)" data-key=4>4</li>
            <li class="k-list" onclick="getnum(5)" data-key=5>5</li>
            <li class="k-list" onclick="getnum(6)" data-key=6>6</li>
            <li class="k-list" onclick="getnum(7)" data-key=7>7</li>
            <li class="k-list" onclick="getnum(8)" data-key=8>8</li>
            <li class="k-list" onclick="getnum(9)" data-key=9>9</li>
            <li class="k-list" onclick="getnum(10)" data-key='10'></li>
            <li class="k-list" onclick="getnum(0)" data-key=0>0</li>
            <li class="k-list del" onclick="del()"><img src="../../image/del.png" alt=""></li>
        </ul>
    </div>
</body>
<script src="../../script/jquery.js"></script>
<script src="../../script/api.js"></script>
<script src="../../script/ffkj.js"></script>
<script src="../../script/vue.js"></script>
<script>
    var view = new Vue({
        el: '#view'
    })
    var userid = $api.getStorage('userid');
    apiready = function () {}

    var payPwd = [];
    // 删除
    function del() {
        if (payPwd.length == 0) {
            return;
        }
        $('.w-list').eq(payPwd.length - 1).removeClass('num');
        payPwd.pop();
    }
    var fristPwd;
    // 点击数字
    function getnum(num) {
        if (num == 10) {
            return;
        }
        payPwd.push(num);
        console.log(payPwd);
        $('.w-list').eq(payPwd.length - 1).addClass('num');

        if (payPwd.length == 6) {
            var w = payPwd.join('');
            console.log(w);
            // 第一次输入
            if (!fristPwd) {
                fristPwd = w;
                $('h3').text('请再次设置支付密码');
                payPwd = [];
                $('.w-list').removeClass('num');
                return;
            }
            // 第二次输入
            if (fristPwd != w) {
                api.toast({
                    msg: '两次密码不一致'
                })
                return;
            }
            // 两次密码一致
            _ajax('home/Withdraw/setPwd?userid=' + userid + '&password=' + w , function (ret, err) {
                console.log(JSON.stringify(ret))
                console.log(JSON.stringify(err))
                if (ret && ret.code == 200) {
                    _send('pay_refresh');
                    _msg('设置成功');
                    setTimeout(function () {
                        api.closeFrame();
                    }, 800)
                } else {
                    _msg('设置失败');
                }
            })
        }
    }
</script>

</html>